package com.rabbitmq.delay.cousmer;

import com.rabbitmq.client.Channel;
import com.rabbitmq.delay.config.RabbitLazyConfigure;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


/**
 * @Author: hualao
 * @Version: 0.0.1V
 * @Date: 2018/10/25
 * @Description: 消费消息
 **/
@Component
public class LazyConsumer {

    @RabbitListener(queues = {RabbitLazyConfigure.REGISTER_QUEUE_NAME})
    public void listenerDelayQueue(String msg, Message message, Channel channel) {
        System.out.println("[listenerDelayQueue 监听的消息] - [消费时间] -> "+ LocalDateTime.now()+"-[消费信息] -> "+ msg);
//        try {
//            //通知 MQ 消息已被成功消费,可以ACK了
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            //如果报错了,那么我们可以进行容错处理,比如转移当前消息进入其它队列
//
//        }
    }
}
